winsafe\dshow\com_interfaces/
ienumpins.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::dshow::{iterators::*, vts::*};
6use crate::ole::privs::*;
7use crate::prelude::*;
8
9com_interface! { IEnumPins: "56a86893-0ad4-11ce-b03a-0020af0ba770";
10	/// [`IEnumPins`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nn-strmif-ienumpins)
11	/// COM interface.
12	///
13	/// Automatically calls
14	/// [`IUnknown::Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
15	/// when the object goes out of scope.
16}
17
18impl dshow_IEnumPins for IEnumPins {}
19
20/// This trait is enabled with the `dshow` feature, and provides methods for
21/// [`IEnumPins`](crate::IEnumPins).
22///
23/// Prefer importing this trait through the prelude:
24///
25/// ```no_run
26/// use winsafe::prelude::*;
27/// ```
28pub trait dshow_IEnumPins: ole_IUnknown {
29	/// Returns an iterator over the [`IPin`](crate::IPin) elements which calls
30	/// [`IEnumPins::Next`](crate::prelude::dshow_IEnumPins::Next) internally.
31	///
32	/// # Examples
33	///
34	/// ```no_run
35	/// use winsafe::{self as w, prelude::*};
36	///
37	/// let pins: w::IEnumPins; // initialized somewhere
38	/// # let pins = unsafe { w::IEnumPins::null() };
39	///
40	/// for pin in pins.iter() {
41	///     let pin = pin?;
42	///     // ...
43	/// }
44	/// # w::HrResult::Ok(())
45	/// ```
46	#[must_use]
47	fn iter(&self) -> impl Iterator<Item = HrResult<IPin>> + '_ {
48		IenumpinsIter::new(self)
49	}
50
51	/// [`IEnumPins::Next`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ienumpins-next)
52	/// method.
53	///
54	/// Prefer using
55	/// [`IEnumPins::iter`](crate::prelude::dshow_IEnumPins::iter), which
56	/// is simpler.
57	#[must_use]
58	fn Next(&self) -> HrResult<Option<IPin>> {
59		let mut queried = unsafe { IPin::null() };
60		let mut fetched = 0u32;
61
62		match ok_to_hrresult(unsafe {
63			(vt::<IEnumPinsVT>(self).Next)(
64				self.ptr(),
65				1, // retrieve only 1
66				queried.as_mut(),
67				&mut fetched,
68			)
69		}) {
70			Ok(_) => Ok(Some(queried)),
71			Err(hr) => match hr {
72				co::HRESULT::S_FALSE => Ok(None), // no pin found
73				hr => Err(hr),                    // actual error
74			},
75		}
76	}
77
78	fn_com_noparm! { Reset: IEnumPinsVT;
79		/// [`IEnumPins::Reset`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ienumpins-reset)
80		/// method.
81	}
82
83	/// [`IEnumPins::Skip`](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-ienumpins-skip)
84	/// method.
85	fn Skip(&self, count: u32) -> HrResult<bool> {
86		okfalse_to_hrresult(unsafe { (vt::<IEnumPinsVT>(self).Skip)(self.ptr(), count) })
87	}
88}